<template>
  <view class="messages-container">
    <!-- 顶部标题栏 -->
    <view class="header">
      <view class="back-icon" @click="navigateBack">
        <text class="iconfont icon-back">&lt;</text>
      </view>
      <text class="title">消息</text>
    </view>

    <!-- 消息列表 -->
    <view class="message-list">
      <view 
        class="message-item" 
        v-for="(message, index) in messages" 
        :key="index"
        @click="viewMessageDetail(message)"
      >
        <!-- 头像 -->
        <view class="avatar-container">
          <image 
            class="avatar" 
            :src="message.type === 'system' ? '/static/system-avatar.png' : message.avatar"
            mode="aspectFill"
          ></image>
          <view class="unread-dot" v-if="!message.isRead"></view>
        </view>

        <!-- 消息内容 -->
        <view class="content">
          <view class="message-header">
            <text class="name">{{message.name}}</text>
            <text class="time">{{message.time}}</text>
          </view>
          <text class="preview">{{message.preview}}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      messages: [
        {
          id: 1,
          type: 'system',
          name: '系统通知',
          avatar: '/static/system-avatar.png',
          preview: '您的换班申请已通过审核，请及时查看',
          time: '10:30',
          isRead: false
        },
        {
          id: 2,
          type: 'user',
          name: '张飞',
          avatar: '/static/avatar1.png',
          preview: '好的，那就这么说定了，明天见',
          time: '昨天',
          isRead: true
        },
        {
          id: 3,
          type: 'system',
          name: '系统通知',
          avatar: '/static/system-avatar.png',
          preview: '您有一条新的换班申请待处理',
          time: '昨天',
          isRead: false
        },
        {
          id: 4,
          type: 'user',
          name: '李四',
          avatar: '/static/avatar2.png',
          preview: '收到，感谢您的回复',
          time: '周一',
          isRead: true
        }
      ]
    }
  },
  methods: {
    navigateBack() {
      uni.navigateBack()
    },
    viewMessageDetail(message) {
      uni.navigateTo({
        url: `/pages/profile/messages/detail/index?id=${message.id}`
      })
    }
  }
}
</script>

<style lang="scss">
.messages-container {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.header {
  height: 90rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ffffff;
  position: relative;
  padding: 0 30rpx;
  border-bottom: 1rpx solid #f0f0f0;
}

.back-icon {
  position: absolute;
  left: 30rpx;
  font-size: 36rpx;
  color: #333;
}

.title {
  font-size: 36rpx;
  font-weight: 500;
  color: #333;
}

.message-list {
  background-color: #ffffff;
}

.message-item {
  display: flex;
  align-items: center;
  padding: 24rpx 30rpx;
  border-bottom: 1rpx solid #f5f5f5;
}

.avatar-container {
  position: relative;
  margin-right: 20rpx;
}

.avatar {
  width: 80rpx;
  height: 80rpx;
  border-radius: 8rpx;
}

.unread-dot {
  position: absolute;
  top: -6rpx;
  right: -6rpx;
  width: 16rpx;
  height: 16rpx;
  background-color: #ff4d4f;
  border-radius: 50%;
}

.content {
  flex: 1;
  overflow: hidden;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8rpx;
}

.name {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

.time {
  font-size: 24rpx;
  color: #999;
}

.preview {
  font-size: 26rpx;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style> 